import json
import os

from data.config.Path import SAVE, CONFIG

def pip2Ui(val):
    """
    向UI文件发出命令通知
    :return:
    """
    with open("./plugin/goodUi/tip.txt", 'w') as f:
        f.write(val)



def JRead(path):
    with open(path, 'r', encoding='utf-8') as f:
        return json.load(f)


def JReadConfig(config):
    return JRead(os.path.join(CONFIG, config)+".conf" )


def JReadSave(saveName, filename):
    return JRead(f"{SAVE}/{saveName}/{filename}.json")



def JWrite(path, data):
    with open(path, 'w', encoding='utf-8') as f:
        json.dump(data, f, ensure_ascii=False)


def JWriteConfig(config, data):
    JWrite(os.path.join(CONFIG, config + ".conf"), data)



def JWriteSave(saveName, filename, data):
    print(f"存储: {SAVE}{saveName}/{filename}.json")
    JWrite(f"{SAVE}{saveName}/{filename}.json", data)